package com.me.libgdx_test;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;

public class ActivityIndex implements Screen{
	
	ActivityMain game;
	Stage stage;
	SpriteBatch batch;
	ClassSkinReference skin;
	ClassLogDisplay logger;
	Point dimensions;
	
	public ActivityIndex(final ActivityMain game){
		this.game = game;
		//There needs to be a loading screen here for when the json data is sent/received from the server
		logger = new ClassLogDisplay("ActivityIndex");
		logger.print(String.valueOf(Gdx.graphics.getWidth()) + "x" + String.valueOf(Gdx.graphics.getHeight()));
		batch = new SpriteBatch();
		logger.print("Stage");
		stage = new Stage();
		logger.print("Skin Reference");
		skin = game.skin;
		
		logger.print("Dimensions");
		
		int width = Gdx.graphics.getWidth();
		int height = Gdx.graphics.getHeight();
		dimensions = new Point(width, height);
		
		int button_width = width/2;
		int button_height = height/9;
		
		logger.print("Input");
		
		Gdx.input.setInputProcessor(stage);
		
		logger.print("Before Stage");
		
		Table table = new Table();
		table.setFillParent(true);
		stage.addActor(table);
		
		final Label title_label = new Label("Pocket Quest", skin.get_skin());
		title_label.setPosition(1*width/10, 5*height/6);
		title_label.setSize(width/10, height/10);
		title_label.setFontScale(10);
		table.add(title_label).width(2*width/3).height(height/6).padBottom(height/15);
		table.row();
		
		logger.print("Before Start");
		
		final TextButton Start_Quest = new TextButton("Start Quest", skin.get_button_skin());
		table.add(Start_Quest).width(button_width).height(button_height).pad(10);
		table.row();
		Start_Quest.addListener(new ChangeListener() {
			public void changed (ChangeEvent event, Actor actor) {
				game.setScreen(game.selectScreen);
			}
		});
		
		logger.print("After Start");
		
		final TextButton Visit_Town = new TextButton("Visit Town", skin.get_button_skin());
		table.add(Visit_Town).width(button_width).height(button_height).pad(10);
		table.row();
		Visit_Town.addListener(new ChangeListener() {
			public void changed (ChangeEvent event, Actor actor) {
				game.setScreen(game.marketScreen);
			}
		});
		
		final TextButton Design_Hero = new TextButton("Design Hero", skin.get_button_skin());
		table.add(Design_Hero).width(button_width).height(button_height).pad(10);
		table.row();
		table.row();
		Design_Hero.addListener(new ChangeListener() {
			public void changed (ChangeEvent event, Actor actor) {
				//game.setScreen(game.gameScreen);
			}
		});
		
		final TextButton Player_Info = new TextButton("Player Info", skin.get_button_skin());
		table.add(Player_Info).width(button_width).height(button_height).pad(10);
		Player_Info.addListener(new ChangeListener() {
			public void changed (ChangeEvent event, Actor actor) {
				game.setScreen(game.gameInfoScreen);
			}
		});
		logger.print("Starting Render");
	}

	@Override
	public void render(float delta) {
		Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
		stage.draw();
		Table.drawDebug(stage);
	}

	@Override
	public void resize(int width, int height) {
		stage.setViewport(width, height, false);
	}

	@Override
	public void show() {
		Gdx.input.setInputProcessor(stage);
		
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		stage.dispose();
		//skin.get_skin().dispose();
	}

}
